﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BartonExtension
{
    public class IDGenerator
    {
        public static long GenerateID()
        {
            byte[] buffer = Guid.NewGuid().ToByteArray();
            return BitConverter.ToUInt16(buffer, 0);
        }

        public static UInt64 StringToInteger(string str)
        {
            UInt64 hashCode = 0;
            if(!str.isNullOrEmpty())
            {
                byte[] byteContents = Encoding.Unicode.GetBytes(str);
                System.Security.Cryptography.SHA256 hash = new System.Security.Cryptography.SHA256CryptoServiceProvider();
                byte[] hashText = hash.ComputeHash(byteContents);
                UInt64 hashStart = BitConverter.ToUInt64(hashText, 0);
                UInt64 hashMedium = BitConverter.ToUInt64(hashText, 8);
                UInt64 hashEnd = BitConverter.ToUInt64(hashText, 24);
                hashCode = hashStart ^ hashMedium ^ hashEnd;
            }
            return hashCode;
        }
    }
}
